package org.jasper.impl.session;

import org.jasper.api.knowledge.InternalKnowledgeBase;
import org.jasper.api.runtime.KieRuntimeEventManager;
import org.jasper.impl.management.DroolsManagementAgent;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by OP038074 on 2018/8/3.
 */
public class StatefulKnowledgeSessionImpl implements KieRuntimeEventManager {

    protected transient InternalKnowledgeBase kBase;
    private AtomicBoolean mbeanRegistered = new AtomicBoolean(false);
    private DroolsManagementAgent.CBSKey mbeanRegisteredCBSKey;

    public void initMBeans(String containerId, String kbaseName, String ksessionName) {
        if (kBase.getConfiguration() != null && kBase.getConfiguration().isMBeansEnabled() && mbeanRegistered.compareAndSet(false, true)) {
            this.mbeanRegisteredCBSKey = new DroolsManagementAgent.CBSKey( containerId, kbaseName, ksessionName );
            DroolsManagementAgent.getInstance().registerKnowledgeSessionUnderName( mbeanRegisteredCBSKey, this );
        }
    }
}
